package com.shenzhen.horselive.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.shenzhen.horselive.R;
import com.shenzhen.horselive.adapter.PayItemAdapter;
import com.shenzhen.horselive.beans.PayWayBean;

import java.util.List;

public class PayViews extends LinearLayout {

    List<PayWayBean.DataBean>  list;
    private  OnItemClick onItemClick;

    public void setOnItemClick(OnItemClick onItemClick) {
        this.onItemClick = onItemClick;
    }

    public void setList(List<PayWayBean.DataBean> list) {
        this.list = list;
        if (adapter!=null)
        {
            adapter.setNewInstance(list);
        }
    }

    public PayViews(Context context) {
        super(context);
        initViews();
    }
    public PayViews(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        initViews();
    }


    RecyclerView  recyclerView;
    PayItemAdapter  adapter;
    TextView  title;
    private void initViews() {
        inflate(getContext(),R.layout.item_pay_views,this);
        recyclerView = findViewById(R.id.recyclerview);
        title  =findViewById(R.id.tv_text1);
        adapter = new PayItemAdapter(R.layout.item_pay);
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        recyclerView.setAdapter(adapter);
        adapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
                PayViews.this.adapter.setSelection(position);
                if (onItemClick!=null)
                {
                    onItemClick.onclick();
                }
            }
        });
    }


    public  PayWayBean.DataBean  getPayWayItem()
    {
        if (list!=null&&list.size()>0)
        {
            return list.get(adapter.getSelection());
        }
        return null;
    }


    public  void   setNone()
    {
        if (adapter!=null)
        {
            adapter.setSelection(-1);
        }
    }

    public  void   setOne()
    {
        if (adapter!=null)
        {
            adapter.setSelection(0);
            adapter.notifyDataSetChanged();
        }
    }


    public void  setTitleGone()
    {
        title.setVisibility(GONE);
    }



    public  interface   OnItemClick{
      void   onclick();
    }

}





